package com.group56.viewmodel;

import com.group56.model.dao.Impl.VideoDAOImpl;
import com.group56.model.dao.VideoDAO;
import com.group56.model.entity.Video;
import com.group56.view.userend.video_module.VideoDetailController;
import com.group56.viewmodel.dto.CustomerDTO;
import com.group56.viewmodel.dto.VideoDTO;
import lombok.NonNull;

public class VideoInfoViewModel implements ViewModel{
    private static VideoInfoViewModel videoInfoViewModel;
    public static VideoInfoViewModel getInstance(@NonNull String name ){
        if (videoInfoViewModel==null||!videoInfoViewModel.videoDTO.getName().equals(name)){
            videoInfoViewModel=new VideoInfoViewModel(name);
        }
        return videoInfoViewModel;
    }
    private final VideoDAO videoDAO=new VideoDAOImpl();
    public VideoInfoViewModel(String name){
        Video video=videoDAO.selectByName(name);
        this.videoDTO=new VideoDTO(video);
    }
    private VideoDTO videoDTO;
    @Override
    public void updateToModel() {
        videoDAO.update(videoDTO.parseVideo(), VideoDetailController.videoName);

    }

    @Override
    public void updateFromModel() {
        Video video=videoDAO.selectByName(videoDTO.getName());
        this.videoDTO.updateVideo(video);
    }
    public VideoDTO getVideoDTO(){return videoDTO;}
}
